package com.hirsi.module.department.vo.result;

import cn.hutool.core.collection.CollUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hirsi.core.expand.TreeNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@ApiModel("组织机构树")
@Data
public class DepartmentTreeResult implements TreeNode<DepartmentTreeResult, Integer> {

    @ApiModelProperty("部门id")
    private Integer id;

    @JsonIgnore
    @ApiModelProperty(value = "父级部门id", position = 1)
    private Integer pid;

    @ApiModelProperty(value = "部门名称", position = 2)
    private String name;

    @ApiModelProperty(value = "子级部门", position = 3)
    private List<DepartmentTreeResult> children;

    @ApiModelProperty(value = "部门成员人数", position = 4)
    private Integer memberNum;

    public Integer getMemberNum() {
        if (CollUtil.isNotEmpty(children)) memberNum += children.stream().mapToInt(DepartmentTreeResult::getMemberNum).sum();
        return memberNum;
    }

    @Override
    public Integer getNodeId() {
        return id;
    }

    @Override
    public Integer getParentNodeId() {
        return pid;
    }
}
